/*
 * @Descripttion: 删除命令
 * @Author: 人生只如初见
 * @Date: 2021-09-23 17:01:37
 * @LastEditors: 人生只如初见
 * @LastEditTime: 2021-09-24 11:10:52
 */
import Command from './Command.js'
import * as THREE from "three";

export class DeleteMeshCommand extends Command {
  constructor(object, editor) {
    super(editor)
    this.type = 'DeleteMeshCommand';
    this.inMemory = true
    this.object = object;
    if (object !== undefined) {
      this.name = '删除模型:' + object.name;
    }
  }
  /** 重做 */
  redo() {
    this.editor.removeMesh(this.object)
  }
  /** 撤销 */
  undo() {
    this.editor.addMesh(this.object)
  }
  /** 把物体转成json字符串 */
  toJSON() {
    var output = super.toJSON.call(this);
    output.object = this.object.toJSON();
    return output;
  }
  /** 根据json字符串生成物体 */
  fromJSON(json) {
    super.fromJSON.call(this, json);
    this.object = this.editor.objectByUuid(json.object.object.uuid);
    if (this.object === undefined) {
      var loader = new THREE.ObjectLoader();
      this.object = loader.parse(json.object);
    }
  }
}
